<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- 兼容性 -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <title>计划编制-主项节点计划列表</title>
    <script src="/scripts/boot.js"></script>
    <style>
        html,body{
            margin:0;padding: 0;border:0;width:100%;height:100%;overflow:hidden;
        }
        body{
            background: #ffffff!important;
            padding:20px;
        }
    </style>
</head>
<body>
<div id="viewForm">
    <div class="title-list mb-20"><span class="title-listbg"></span><span>项目主项节点计划编制</span></div>
    <div>
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <div class="mb-20 position-rel">
                        <span>计划名称</span><input type="text" id="name" name="name" class="mini-textbox w220" readonly/>
                   		<input  class="mini-hidden w220" id="planId" name="planId"  />
                        <div class="position-abs">
                            <a class="plan-btn mR-20"  onclick="view.calsDate()"><span class="add-bg"></span>自动推算时间</a>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit" style="height:400px;">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" url="/mainPlanNode/listByPage" sizeList="[5,10,20,50]" pageSize="20"  idField="id" multiSelect="true">
            <div property="columns">
                <div field="NO" headerAlign="center" width="40" align="center">编号</div>
                <div field="business" width="100" headerAlign="center"  align="center" allowSort="true">业务板块</div>
                <div field="nodeName" width="120" headerAlign="center" allowSort="true">节点名称</div>
                <div field="nodeProperty" width="100" headerAlign="center" align="center" allowSort="true">节点性质</div>
                <div field="completeStandard" width="120" headerAlign="center" allowSort="true">完成标准</div>
                <div field="deadline" width="100" headerAlign="center" align="center" allowSort="true">标准工期(天)</div>
                <div field="deadlineDesc" width="120" headerAlign="center" allowSort="true">工期说明</div>
                <div field="beginDate" width="100" headerAlign="center" align="center" allowSort="true">计划开始时间</div>
                <div field="endDate" width="100" headerAlign="center" align="center" allowSort="true">计划结束时间</div>
                <div field="companyName" width="120" headerAlign="center" allowSort="true">责任单位</div>
                <div field="officeName" width="120" headerAlign="center" allowSort="true">责任部门</div>
                <div field="postName" width="120" headerAlign="center" allowSort="true">责任岗位</div>
                <div field="remark" width="120" headerAlign="center" allowSort="true">备注</div>
            </div>
        </div>
    </div>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.audit()">发起审批</a>
    </div>
</div>
<script type="text/javascript">
    var post_flag,form,state,datas,check=false,calsDate=false;
    var view = {
   		calsDate:function(){
   			if(calsDate){
   				mini.alert("已经推算过")
   				return;
   			}
   			var pid = $("#planId").val();
			calsDate=true;
 			$.ajax({
 				url:"/mainPlan/calsDealine",
 				data:{"planId":pid},
 				success:function(data){
 					if(data.state){
 						mini.get("datagrid1").reload();
 						check=true;
 					}else{
 						mini.alert(data.message);
 						calsDate=false;
 					}
 				}
 			})	  			
   		},
        init: function () {
            post_flag = false; //设置一个对象来控制是否进入AJAX过程
            mini.parse();
            form = new mini.Form("#viewForm");
            mini.get("datagrid1").load();
        },
        //审核
        audit:function () {
        	if(!check){
        		mini.alert("请先推算时间在提交审核");
        		return;
        	}
   			var pid = $("#planId").val();
           $.ajax({
				type : "post",
				url : "/loggerService/startPost",
				data : {"id":pid,"formSign":"CDJHGLJHBZJH_01","workFlowId":"CDJHGLJHBZJHSP","jumpUrl":"/planning/drafts/workflow.html?id="+pid,"url":"/act/taskApi/start","exampleEntity":"plan"},
				success : function(msg) {
					if(msg.message==="ok"){
						view.updateAuditState(pid);
					}
				}
			}); 
        }, //改变数据状态
        updateAuditState: function(pid){
        	 $.ajax({
	        	  url:"/keyPlan/audit",
	        	  data:{"planId":pid},
	        	  success:function(data){
	        		  mini.alert(data.message, "提醒");
	        		  if(data.state){
	        			  CloseWindow('close')
	        		  }
	        	  }
        	 });
		},
        //    数据展示
        SetData: function (data) {
            data = mini.clone(data);
            console.log(data)
            mini.get("datagrid1").load({'plan.id': data.id});
            mini.get("name").setValue(data.name);
            mini.get("planId").setValue(data.id);
        }
    };
    view.init();
</script>
</body>
</html>